package com.znsd.stu.controllor;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.znsd.entitys.Leave;
import com.znsd.entitys.Cwj_SpecialtyInfo;
import com.znsd.entitys.Users;
import com.znsd.stu.service.Cwj_LeaveService;

@Controller
public class Cwj_LeaveControllor {
	@Autowired
	private Cwj_LeaveService leaveService;
	
	@RequestMapping(value = "goleave", method = RequestMethod.GET)
	public String goleave(Integer classId,HttpServletRequest  request) {
		HttpSession session=request.getSession();
		session.setAttribute("classId",classId);
		return "admin/leaves";
	}
	
	@RequestMapping(value = "updateLeave", method = RequestMethod.GET)
	public String updateLeave(Integer lid,Integer state,HttpServletRequest  request) {
		HttpSession session = request.getSession();
		Users user=(Users) session.getAttribute("user");
		leaveService.updateLeave(lid, state,user.getUser_id(),new Date());
		
		
		return "admin/leaves";
	}
	
	
	@ResponseBody
	@RequestMapping("leaveList")
	public Map<String,Object> leaveList(HttpServletRequest  request) {
		List<Leave> list=leaveService.getAll();
		List<Leave> list1=new ArrayList<Leave>();
		HttpSession session=request.getSession();
		Integer classId=(Integer) session.getAttribute("classId");
		System.out.println(classId);
		for (Leave leave : list) {
			if(leave.getStudent_id().getClassId()==classId) {
				list1.add(leave);
			}
		}
		
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("rows",list1);
		map.put("total",list1.size());
		return map;
	}
	
	
}
